//循环队列的实现
var myFunc = function(k){
    this.head = -1;
    this.tail = -1;
    this.len = k;
    this.data = [];

}
myFunc.prototype.enQueue = function(value){//往队列中插入一条数据如果插入成功则返回true
    if(this.isFull()==true){
        return false;
    }
    if(this.isEmpty()==true){
        this.head=0;
    }
    this.tail = (this.tail + 1) %this.len;
    this.data[this.tail] = value;
    return true;
}

myFunc.prototype.front = function(){//获取队列第一个元素 如果队列为空 返回-1
    if(this.isEmpty()==true){
        return -1;
    }
    return this.data[this.head];
}
myFunc.prototype.rear = function(){//获取队尾元素 如果为空则返回-1
    if(this.isEmpty()==true){
        return -1;
    }
    return this.data[this.tail]

}
myFunc.prototype.deQueue = function(){//删除一个元素 成功返回true
    if(this.isEmpty()==true){
        return false;
    }
    if(this.head== this.tail){
        this.head=-1;
        this.tail=-1;
        return true;
    }
    this.head = (this.head+1)%this.len;
    return true;
}
myFunc.prototype.isEmpty = function(){//检查队列是否为空
    return this.head==-1
}
myFunc.prototype.isFull = function(){//检查队列是否已满
    return((this.tail +1)%this.len==this.head)
}
let obj = new myFunc(3)
let p1 = obj.enQueue(1)
let p2 = obj.enQueue(2)
let p3 = obj.enQueue(3)
let p4 = obj.enQueue(4)
let p7 = obj.rear()
let p5 = obj.deQueue()
let p6 = obj.front()
console.log(p7)